//
// Created by 谢哲 on 2021/5/19.
//

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    int n;
    cin >> n;

    int cur_sum = 0, cur_min = 0;
    int ans = -99999999;
    for (int i=0; i<n; ++i) {
        int a;
        cin >> a;
        cur_sum += a;
        ans = max(ans, cur_sum - cur_min);
        cur_min = min(cur_min, cur_sum);
    }

    cout << ans;
}
